angular.module('functions', [])
    .controller('functionsCtrl', ['$scope', 'httpService', '$localStorage', '$rootScope', '$state', function($scope, httpService, $localStorage, $rootScope, $state) {
        
        function getPersion(id) {
            if (id) {
                httpService.query('web/users/' + id).then(function(res) {
                    if (res.code == 200) {
                        $localStorage.user = $rootScope.user = user = res.user;
                        $scope.addons = res.user.addons;
                    }
                });
            } else {
                $state.go('login');
            }

        };

        if ($localStorage.user) {
            getPersion($localStorage.user.id);
        }

        $scope.setPlugin = function(serial_number) {
            console.log('serial_number', serial_number);
            if(serial_number == '5mutian_set_check') {
                $state.go('mine.node');
            }
        };

        // function getAddons() {
        // 	httpService.query('web/users/fetch_addons', {limit: 99999}).then(function(res) {
        // 		console.log('res', res)
        // 		if(res.code == 200) {
        // 			$scope.addons = res.addons;
        // 		}
        // 	});
        // }
        // getAddons();
    }]);
